package collections;

import java.util.LinkedList;

public class StackTest {
	public static void main(String[] args) {
		/*
		MyStack ms = new MyStack();
		ms.push("one");
		ms.push("two");
		ms.push("three");
		
		System.out.println(ms.pop());
		System.out.println(ms.peek());
		System.out.println(ms.pop());
		System.out.println(ms.isEmpty());
		System.out.println(ms.pop());
		System.out.println(ms.isEmpty());
		*/
		
		/*
		MyStack2 ms2 = new MyStack2();
		ms2.push("one");
		ms2.push("two");
		ms2.push("three");
		
		System.out.println(ms2.pop());
		System.out.println(ms2.peek());
		System.out.println(ms2.pop());
		System.out.println(ms2.isEmpty());
		System.out.println(ms2.pop());
		System.out.println(ms2.isEmpty());
		*/
		
		MyQueue mq = new MyQueue();
		mq.put("one");
		mq.put("two");
		mq.put("three");
		
		System.out.println(mq.get());
		System.out.println(mq.peek());
		System.out.println(mq.get());
		System.out.println(mq.isEmpty());
		System.out.println(mq.get());
		System.out.println(mq.isEmpty());
		
	}
}

class MyStack {
	private LinkedList myList = new LinkedList();
	public void push(Object o) {
		myList.addFirst(o);
	}
	public Object pop() {
		return myList.removeFirst();
	}
	public Object peek() {
		return myList.getFirst();
	}
	public boolean isEmpty() {
		return myList.isEmpty();
	}
}

class MyStack2 {
	private LinkedList myList = new LinkedList();
	public void push(Object o) {
		//myList.addLast(o);
		System.out.println(myList.add(o));
	}
	public Object pop() {
		return myList.removeLast();
	}
	public Object peek() {
		return myList.getLast();
	}
	public boolean isEmpty() {
		return myList.isEmpty();
	}
}



class MyQueue {
	private LinkedList myList = new LinkedList();
	public void put(Object o) {
		myList.addLast(o);
		//System.out.println(myList.add(o));
	}
	public Object get() {
		return myList.removeFirst();
	}
	public Object peek() {
		return myList.getFirst();
	}
	public boolean isEmpty() {
		return myList.isEmpty();
	}
}
